import java.math.BigInteger;
import java.util.Scanner;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/4/7 15:46
 * 求正数数组的最小不可组成和 ---DP  --01背包问题
 *          [min,sum] 看作背包的容量
 *          arr中的值，看作 货物价值
 * 有假币  数学思想，每判断一次，分为三分，num%3==0 的 下次判断的数就是 num/3 .  9：3 3 3
 *                num%3 != 0 的，下次判断就是 num/3 + 1 . 10 : 3  3 4 ; 11: 3 4 4 取 4
 *
 */
public class Day29 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            BigInteger num = scanner.nextBigInteger();
            if (num.equals(BigInteger.ZERO)){
                break;
            }
            System.out.println(count(num));
        }
    }

    private static BigInteger count(BigInteger num) {
        BigInteger three = new BigInteger("3");
        BigInteger count  = new BigInteger("0");
        if (num.equals(BigInteger.ONE)){
            return BigInteger.ZERO;
        }
        if (num.compareTo(three) <= 0){
            return new BigInteger("1");
        }
        while (!num.equals(BigInteger.ONE)){
            if (num.mod(three).equals(BigInteger.ZERO)){
                num = num.divide(three);
            }else {
                num = num.divide(three).add(BigInteger.ONE);
            }
            count =  count.add(BigInteger.ONE);
        }
        return count;
    }
    //----------------------------
    /**
     *	正数数组中的最小不可组成和
     *	输入：正数数组arr
     *	返回：正数数组中的最小不可组成和
     */
    public int getFirstUnFormedNum(int[] arr) {
        int sum = 0;
        int min = arr[0];

        for (int i = 0; i < arr.length; i++) {
            sum+=arr[i];
            min = Math.min(min,arr[i]);
        }
        
        int[] dp = new int[sum+1];
        for (int i = 0; i < arr.length; i++) {
            for (int j = sum; j >= arr[i]; j--) {
                if (dp[j] < dp[j - arr[i]] + arr[i]){
                    dp[j] = dp[j - arr[i]] + arr[i];
                }else {
                    dp[j] = dp[j];
                }
            }
        }
        for (int i = min; i <= sum; i++) {
            if (i != dp[i]){
                return i;
            }
        }
        return sum+1;

    }
}
